package alo.p10;

import alo.p7.Heap;

/**
 * @ClassName HeapSort
 * @Description 堆排序
 * @Author Fanxc
 * @DATE 2021/3/12 9:41
 * @Version 1.0
 */
public class HeapSort {
    public void heapSort(int[] A,int left,int right){
        int N=right-left+1;
        Heap h=new Heap(N,0);
        int old_size,temp;
        h.BuildHeap(h,A,N);
        old_size=h.count;
        for (int i = left; i <=right; i++) {
            temp=h.array[0];
            h.array[0]=h.array[h.count-1];
            h.array[h.count-1]=temp;
            h.count--;
            h.PercolateDown(0);
        }
        h.count=old_size;

    }
}
